struct Response<T> {
    data: T,
    code: i32,
    msg: String
}

impl<T> Response<T> {
    fn successed(data: T) -> Self {
        return Response{data, code: 200, msg: String::from("OK")};
    }
    fn get_data(&self) -> &T {
        return &self.data;
    }
}


/**
 * Trait 类似java interface 但是不是每个方法必须实现
 */
trait IM {
    fn open(&self);
    fn close(&self);
    fn error(&self, err: String);
    fn send(&self, payload: String);
}

struct VideoIM;

impl IM for VideoIM {
    fn open(&self) {
        println!("VideoIM 开始播放视频");
    }

    fn close(&self) {
        println!("VideoIM 关闭视频");
    }

    fn error(&self, err: String) {
        println!("VideoIM 出现错误: {}", err);
    }

    fn send(&self, payload: String) {
        println!("VideoIM 发送数据: {}", payload);
    }
}


fn main() {
    let response = Response::<String>::successed(String::from("Iceman"));
    println!("{} - {} - {}", response.get_data(), response.code, response.msg);
    let video = VideoIM;

    video.open();
    video.send("视频数据".to_string());
    video.error("播放失败".to_string());
    video.close();
}
